<?php
/*
 * Created on Oct 25, 2010
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
include_once("../configure/admin.config.inc.php");	//--> admin global var
include_once("Files.php");							//--> Files
include_once("ImageUtils.php");						//--> ImageUtils

$oFiles		= new Files();		//--> Files
$oImageUtils= new ImageUtils();	//--> Image Utils

$fileName	= $_GET['fileName'];
$height		= $_GET['height'];
$width		= $_GET['width'];
$type		= $_GET['type'];

if(empty($height))
	$height = 0;
	
if(empty($width))
	$width = 0;

$arr_extend_name 	= explode('.',$fileName);
$extend_name 		= $arr_extend_name[count($arr_extend_name) - 1];

$imageid = $arr_extend_name[count($arr_extend_name) - 2];

$homePath;
if($type === 'product'){
	$homePath = IMAGE_PATH_PRODUCT;
	
	$defaultImageFile 	= $homePath . 'noimage.jpg';
	$filepath = $homePath . $oFiles->getDirByID($imageid) . '/' . $imageid . '.' . $extend_name;
	
	if(!file_exists($filepath) || !is_file($filepath)){
		$filepath = $defaultImageFile;
	}
}else if ($type === 'site'){
	$homePath = IMAGE_PATH_SITE;
	
	$defaultImageFile 	= $homePath . 'noimage.jpg';
	$filepath 			= $homePath . $oFiles->getDirByID($imageid) . '/' . $imageid . '.' . $extend_name;
	
	if(!file_exists($filepath) || !is_file($filepath)){
		$filepath = $defaultImageFile;
	}
}else if ($type === 'logo'){
	$homePath = IMAGE_PATH_LOGO;
	
	$defaultImageFile 	= $homePath . 'merchant_noimage_logo.gif';
	$filepath 			= $homePath . $oFiles->getDirByID($imageid) . '/' . $imageid . '.' . $extend_name;	
	
	if(!file_exists($filepath) || !is_file($filepath)){
		$filepath = $defaultImageFile;
	}
}else if ($type === 'url'){
	$homePath = IMAGE_PATH_SITE;
	
	$defaultImageFile 	= $homePath . 'noimage.jpg';
	$filepath 			= base64_decode($fileName);
}else{
	$filepath 			= IMAGE_PATH_SITE . 'noimage.jpg';
	$defaultImageFile 	= IMAGE_PATH_SITE . 'noimage.jpg';
}



//echo 'filepath = ' . $filepath;

//$defaultImageFile = IMAGE_PATH_SITE . 'noimage.jpg';



//echo 'IF_NONE_MATCH = ' . $_SERVER['HTTP_IF_NONE_MATCH'];		
//echo 'path = ' . file_exists($filepath) . '<br>';
//echo 'path = ' . $filepath;
//echo 'width = ' . $width;
//echo 'height = ' . $height;
//exit;

$oImageUtils->RatioAdjuct($filepath, $width, $height, false, true, $defaultImageFile);

?>
